package com.elite.groovy.callback
import com.elite.groovy.util.EliteBean;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.elite.groovy.util.Util;
import net.sf.json.JSONObject;
/**
 * @author
 *
 */
public class dispatchData implements ServiceBackInvoke{
		private static final Log log=LogFactory.getLog(dispatchData.class);
		private String charset = "utf-8"; //设置字符集
		private int timeout = 100000; //设置请求超时时间
		private int enableSSLflag = 0;	
		public String doCallBack(EliteBean eliteBean, HttpServletRequest request, HttpServletResponse response){
			Util bodyjson = new Util();
			String requestJSONStr =bodyjson.getRequestBody(request, "UTF-8");
			log.debug("inputParamter:"+request.getQueryString());
			
			log.debug("requestJSONStr"+requestJSONStr);
			JSONObject json  = new JSONObject().fromObject(requestJSONStr);
			String report_no=json.getString("report_no");//报案号
			String policy_num=json.getString("policy_num");//保单号
			String license_no=json.getString("license_no");//车牌号
			String insured_name=json.getString("insured_name");//被保险人
			String report_time=json.getString("report_time");//报案时间
			String linker_phone=json.getString("linker_phone");//联系人电话
			String damage_time=json.getString("damage_time");//出险时间
			String accident_course=json.getString("accident_course");//出险经过
			String brand_name=json.getString("brand_name");//车型
			String channel=json.getString("channel");//报案渠道
				
			JSONObject resulterror = new JSONObject();
			try{
				if(report_no==""){
					resulterror.put("retCode", "-1");
					resulterror.put("retMessage", "报案号不能为空");
					return resulterror;
				}
				if(policy_num==""){
					resulterror.put("retCode", "-1");
					resulterror.put("retMessage", "保单号不能为空");
					return resulterror;
				}
				String sql="insert into OBT_SELF_LIST (self_id,report_no,policy_num,license_no,insured_name,report_time,accident_course,LINKER_PHONE,DAMAGE_TIME,BRAND_NAME,channel,create_time,dispatch_type) values(sysguid(),'"+report_no+"','"+policy_num+"','"+license_no+"','"+insured_name+"','"+report_time+"','"+accident_course+"','"+linker_phone+"','"+damage_time+"','"+brand_name+"','"+channel+"',sysdate,'退回改派')";
				def updatesqlresult=eliteBean.update(sql,"dataSource");
				log.debug("updatesqlresult:"+updatesqlresult);
				resulterror.put("retCode", "1");
				resulterror.put("retMessage", "调用成功");
				return resulterror;
				
			}catch(Exception e){
				resulterror.put("retCode", "-1");
				resulterror.put("retMessage", "接口调用失败:"+e);
				log.debug(e);
				return resulterror;
			}
			
		}
}